package com.ljh.controller;

import com.ljh.feign.OrderFeign;
import com.ljh.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderFeign orderFeign;
    @GetMapping("/findAllByUid")
    @ResponseBody
    public OrderVO findAllByUid(@RequestParam("page") int page, @RequestParam("limit") int limit, HttpSession session){
        User user = (User)session.getAttribute("user");
        return orderFeign.findAllByUid(user.getId(),page,limit);
    }
    @GetMapping("/save/{mid}")
    public String save(@PathVariable("mid") long mid,HttpSession session){
        Menu menu=new Menu();
        Order order=new Order();
        User user =(User) session.getAttribute("user");
        menu.setId(mid);
        order.setMenu(menu);
        order.setDate(new Date());
        order.setUser(user);
        orderFeign.save(order);
        return "redirect:/account/redirect/order";
    }
    @GetMapping("/findAllByState")
    @ResponseBody
    public OrderVO findAllByState(@RequestParam("page") int page,@RequestParam("limit") int limit){
        return orderFeign.findAllByState(0,page,limit);
    }
    @GetMapping("/updateState/{id}/1")
    public String updateState(@PathVariable("id") long id,HttpSession session){
        Admin admin = (Admin) session.getAttribute("admin");
        orderFeign.updateState(id,admin.getId(),1);
        return "redirect:/account/redirect/order_handler";
    }
}
